<?php
/**
 * 常用助手类
 * 引入组件
 * <pre>
 * file:/config/main.php
 * 'imports' => array(
 *  'lib.helpers.utils.CUtil',
 * ),
 * </pre>
 * 使用组件
 * <pre>
 * $sumValue = Util::math()->sum(1, 2);
 * </pre>
 * @author yangdongqi <yangdongqi@hayzone.com>
 * @package lib.helpers.utils
 */
class CUtilHelper {
	
	protected static $_instance = null;
	protected static $_utilInstances = array();
	protected static $_classes = array(
		'CMathUtil' => 'lib.helpers.utils.CMathUtil',
		'CStringUtil' => 'lib.helpers.utils.CStringUtil',
		'CArrayUtil' => 'lib.helpers.utils.CArrayUtil',
		'CDateUtil' => 'lib.helpers.utils.CDateUtil',
		'CMiscUtil' => 'lib.helpers.utils.CMiscUtil',
		'CImageUtil' => 'lib.helpers.utils.CImageUtil',
	);
	
	/**
	 * 数学
	 * @return CMathUtil
	 */
	public static function math() {
		return self::getUtilInstance('CMathUtil');
	}

	/**
	 * 图像
	 * @return CImageUtil
	 */
	public static function img() {
		return self::getUtilInstance('CImageUtil');
	}
	
	/**
	 * 字符串
	 * @return CStringUtil
	 */
	public static function string() {
		return self::getUtilInstance('CStringUtil');
	}
	
	/**
	 * 数组
	 * @return CArrayUtil
	 */
	public static function arr() {
		return self::getUtilInstance('CArrayUtil');
	}
	
	/**
	 * 时间日期
	 * @return CDateUtil
	 */
	public static function date() {
		return self::getUtilInstance('CDateUtil');
	}
	
	/**
	 * 杂项
	 * @return CMiscUtil
	 */
	public static function misc() {
		return self::getUtilInstance('CMiscUtil');
	}
	
	
	protected static function getUtilInstance($name) {
		if(!isset(self::$_utilInstances[$name])) {
			Yii::import(self::$_classes[$name]);
			self::$_utilInstances[$name] = new $name;
		}
		return self::$_utilInstances[$name];
	}
	
	
	
}

?>